import Layer from '../../core/Layer';
import Text from '../../base/Text';

export default class extends Layer {
    constructor(canvas, style, data = []) {
        super(canvas, style);
        this.data = data;
    }

    build() {
        this.childs.splice(0);
        const yStep = this.height / (this.data.length - 1);
        for (let i = 0; i < this.data.length; i++) {
            const txt = new Text(this.canvas, {
                fontSize: this.fontSize,
                fontFamily: this.fontFamily,
                color: this.color,
                text: this.data[i],
                type: Text.TYPE.FILL,
                textAlign: this.textAlign,
                position: 'absolute',
            });
            if (i === 0) {
                txt.bottom = i * yStep;
            } else if (i === this.data.length -  1) {
                txt.bottom = i * yStep - txt.height;
            } else {
                txt.bottom = i * yStep - txt.height / 2;
            }
            if (this.textAlign === 'right') {
                txt.left = this.width;
            } else if (this.textAlign === 'left') {
                txt.left = 0;
            }
            this.addChild(txt);
        }
    }
}
